package com.frogs.ucenter.v1.service.impl.aop;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.response.Response;
import com.frogs.ucenter.v1.util.ApiConstants;

@Aspect
@Service(ApiConstants.VERSION+"userOrderAccumulatesAopImpl")
public class UserOrderAccumulatesAopImpl {
	
	private static final Logger log = LoggerFactory.getLogger(UserOrderAccumulatesAopImpl.class);
	
	@Resource(name = ApiConstants.VERSION + "baseTaskAop")
	private BaseTaskAop baseTaskAop;
	

	
	@AfterReturning(pointcut="execution(* com.frogs.ucenter.v1.controller.UserOrderController.accumulates(..)) || "
							+ "execution(* com.frogs.ucenter.v1.controller.UserAccountInfoController.bindPhone(..)) ||"
							+ "execution(* com.frogs.ucenter.v1.controller.UserAccountInfoController.bindEmail(..))",returning="result")
	public void doAfterReturning(JoinPoint jp, Response result){
		try {
			Integer code = result.getCode();
			if(1 != code ){
				return;
			}
			HttpServletRequest req = (HttpServletRequest)jp.getArgs()[0];//切入点方法入参
			HttpRequestInfo requestInfo = new HttpRequestInfo(req);
	    	int userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
	    	baseTaskAop.updateUserLevel(userId);
		} catch (Exception e) {
			log.error("func[doAfterReturning] jp[" + jp + "] result[" + result + "] error[" + e.getMessage() + "]", e);
		}
	}
}
